Extend the xc_linux_save interface to take a callback function for handling the
authoremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Tue, 10 Jan 2006 14:23:56 +0000 (14:23 +0000)
committeremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Tue, 10 Jan 2006 14:23:56 +0000 (14:23 +0000)
suspend, and push the printf("suspend") out of xc_linux_save and into xc_save.
This means that xc_linux_save can be used without the xc_save wrapper if
desired.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/libxc/xc_ia64_stubs.c
tools/libxc/xc_linux_save.c
tools/libxc/xenguest.h
tools/xcutils/xc_save.c

index 2a25802c3bf9e698f075275d515872df3422fd55..2936415be0892702ca8f981b553276527fd1eac9 100644 (file)
@@ -23,7 +23,7 @@ unsigned long xc_ia64_fpsr_default(void)
 }
 
 int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, 
-                  uint32_t max_factor, uint32_t flags)
+                  uint32_t max_factor, uint32_t flags, int (*suspend)(void))
 {
     PERROR("xc_linux_save not implemented\n");
     return -1;
index b619bdf7b4d37011dc1b4426a41ff960da8db44b..927cc6cbd54da9bf618bfeafb59a3b9b291d65a1 100644 (file)
@@ -357,21 +357,14 @@ static int analysis_phase(int xc_handle, uint32_t domid, int max_pfn,
 }
 
 
-static int suspend_and_state(int xc_handle, int io_fd, int dom,       
-                             xc_dominfo_t *info,
+static int suspend_and_state(int (*suspend)(int), int xc_handle, int io_fd,
+                             int dom, xc_dominfo_t *info,
                              vcpu_guest_context_t *ctxt)
 {
     int i = 0;
-    char ans[30];
 
-    printf("suspend\n");
-    fflush(stdout);
-    if (fgets(ans, sizeof(ans), stdin) == NULL) {
-        ERR("failed reading suspend reply");
-        return -1;
-    }
-    if (strncmp(ans, "done\n", 5)) {
-        ERR("suspend reply incorrect: %s", ans);
+    if (!(*suspend)(dom)) {
+        ERR("Suspend request failed");
         return -1;
     }
 
@@ -568,7 +561,7 @@ static unsigned long *xc_map_m2p(int xc_handle,
 
 
 int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, 
-                  uint32_t max_factor, uint32_t flags)
+                  uint32_t max_factor, uint32_t flags, int (*suspend)(int))
 {
     xc_dominfo_t info;
 
@@ -748,7 +741,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
         
         last_iter = 1;
         
-        if (suspend_and_state( xc_handle, io_fd, dom, &info, &ctxt)) {
+        if (suspend_and_state(suspend, xc_handle, io_fd, dom, &info, &ctxt)) {
             ERR("Domain appears not to have suspended");
             goto out;
         }
@@ -1054,7 +1047,8 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
                 DPRINTF("Start last iteration\n");
                 last_iter = 1;
                 
-                if (suspend_and_state(xc_handle, io_fd, dom, &info, &ctxt)) {
+                if (suspend_and_state(suspend, xc_handle, io_fd, dom, &info,
+                                      &ctxt)) {
                     ERR("Domain appears not to have suspended");
                     goto out;
                 }
index dcd9b6972e7ecc387e32adf66e1ce90560ba9189..c0eb5bcdd3753fe11d42ad6c2ac4eac18ab0c02f 100644 (file)
@@ -22,7 +22,9 @@
  * @return 0 on success, -1 on failure
  */
 int xc_linux_save(int xc_handle, int fd, uint32_t dom, uint32_t max_iters, 
-                  uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */);
+                  uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */,
+                  int (*suspend)(int));
+
 
 /**
  * This function will restore a saved domain running Linux.
index eac8d1ad2b6320ab81c9e563fcd799404cbbcc97..44c470137946127c766845a00d39c0e2fbd8665b 100644 (file)
 #include <err.h>
 #include <stdlib.h>
 #include <stdint.h>
+#include <string.h>
 #include <stdio.h>
 
 #include <xenguest.h>
 
+
+/**
+ * Issue a suspend request through stdout, and receive the acknowledgement
+ * from stdin.  This is handled by XendCheckpoint in the Python layer.
+ */
+static int suspend(int domid)
+{
+    char ans[30];
+
+    printf("suspend\n");
+    fflush(stdout);
+
+    return (fgets(ans, sizeof(ans), stdin) != NULL &&
+            !strncmp(ans, "done\n", 5));
+}
+
+
 int
 main(int argc, char **argv)
 {
@@ -29,5 +47,5 @@ main(int argc, char **argv)
     max_f = atoi(argv[5]);
     flags = atoi(argv[6]);
 
-    return xc_linux_save(xc_fd, io_fd, domid, maxit, max_f, flags);
+    return xc_linux_save(xc_fd, io_fd, domid, maxit, max_f, flags, &suspend);
 }